<?php
defined('JOC') or die;
/**
 * Description of db
 *
 * @author javier
 */
class db
{
  //put your code here
  private $db_instance ;
  private $last_cache_result ;
  
  function __construct( $db_engine = 'mysql' )
  {
    require_once "{$db_engine}.class.php" ;
    $this->db_instance = new $db_engine() ;
  }
  function close()
  {
    return $this->db_instance->close() ;
  }
    /*
   * public function query
   * $sql = string mysql_query 
   * $cache = (true|false) do not use for simple query like "SELECT * FROM any_table ;"
   * $time = in MINUTE
   * $create_cache = (true|false) Save the result into the cache table
   * $free_result = (true|false) In case of found cache record for the current query deleted it
   */
  function query($sql = '' , $cache = true , $time = 1 , $create_chache = true , $free_result = false )
  {
    return $cache  && $this->cache_query($sql,$time,$create_chache,$free_result) ? $this->last_cache_result : $this->db_instance->query($sql,$create_chache);
  }
  function cache_query( $sql = '' , $time = 1 , $free_result = true )
  {
    $this->last_cache_result = $this->db_instance->cache_query($sql,$time,$free_result) ;
    return $this->last_cache_result ;
  }
  function simple_query($sql=''){
  	global $user ;
  	if($user->isAdmin())
  	{
  		return $this->db_instance->simple_query($sql) ;
  	}
  }
  function conected()
  {
    return $this->db_instance->conected() ? TRUE : FALSE ;
  }
}

